﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
using INTEX.DataBase;
using INTEX.DataBase.Tools;
using System.Linq;
using WPFExcelReport.Helpers;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXBL
    {
        public DataSet QueryEKK(string MANDANT, string KRS, string LFD)
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            DataRow dwData;
            DataRow dwEK04 = null;
            DataSet STemp = new DataSet();
            try
            {
                dwData = INTEXDB.ICC_QUERYTB.NewRow();
                dwData["EKKMANDANT"] = MANDANT;
                dwData["EKKAUFKRS"] = KRS;
                dwData["EKKAUFLFD"] = LFD;
                SResult = INTEXDBC.QueryEKKOPF(dwData);
                SReturn.Merge(SResult);
                foreach (DataRow row in SResult.Tables[0].Rows)
                {
                    dwEK04 = row;
                }
                if (dwEK04 == null)
                    return SReturn;
                SResult = INTEXDBC.QueryLIEFDAT(dwData, 5);
                SReturn.Merge(SResult);
                SResult = INTEXDBC.QueryLIEFKO(dwData, 5);
                SReturn.Merge(SResult);

                foreach (DataRow row in SResult.Tables[0].Rows)
                {
                    dwData["ZABMANDANT"] = MANDANT;
                    dwData["ZABNR"] = row["LSKZAHLBED"];
                    STemp = INTEXDBC.QueryZABED(dwData, 1);
                    SReturn.Merge(STemp);
                    dwData["TXTIMANDANT"] = MANDANT;
                    dwData["TXTITXTART"] = "ZAB";
                    dwData["TXTISIND"] = Helper.Left(row["LSKZAHLBED"].ToString() + "V                                                                                       ", 60);
                    STemp = INTEXDBC.QueryTXTKON(dwData, 1);
                    SReturn.Merge(STemp);
                    STemp = Helper.ConvertTXT(STemp.Tables["TXTKON"], INTEXDB.ICC_TXTKON.NewRow());
                    SReturn.Merge(STemp);
                }

                dwData["EKPMANDANT"] = MANDANT;
                dwData["EKPAUFKRS"] = KRS;
                dwData["EKPAUFLFD"] = LFD;
                SResult = INTEXDBC.QueryEKPOS(dwData, 2);
                SResult.Tables[0].TableName = "ICC_EKPOS";
                SReturn.Merge(SResult);
                SResult = INTEXDBC.QueryGSDAT(dwData, 2);
                SReturn.Merge(SResult);
                SResult = INTEXDBC.QueryGSCOLOR(dwData, 3);
                SReturn.Merge(SResult);
                SResult = INTEXDBC.QueryMSSTAMM(dwData, 2);
                SReturn.Merge(SResult);
                SResult = INTEXDBC.QueryQPPROF(dwData, 2);
                SReturn.Merge(SResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return SReturn;
        }
    }
}